// add by yanyj 20180703 start

function transform(extent) {
    return ol.proj.transformExtent(extent, 'EPSG:4326', 'EPSG:3857');
}

// 生成天地图图层(包含注记)
var createTianDiLayer = function() {

    return [
        new ol.layer.Tile({
            title: "天地图路网",
            extent: transform([-180, -90, 180, 90]),
            source: new ol.source.XYZ({
            url: "http://t7.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}"
        })
        }), new ol.layer.Tile({
            title: "天地图注记",
            extent: transform([-180, -90, 180, 90]),
            source: new ol.source.XYZ({
            url: "http://t7.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}"
        })
    })]

};


// page对象
(function (root) {
    root.PageFrame = function (option) {
        $(document).ready(function () {
            option.init();
            option.events();
            option.end();
        });

    }
})(window);


// 点集对象特殊处理
function stringArray2coordinateArray(strArray) {
    let coordinateArray = [];
    // strArray = ["1.2644176275078254E7,2520122.459431299,1.2642893649147162E7,2521333.683097796,1.2641112912057422E7,2521839.8837439246,1.2640803236012341E7,2521257.1049001315,1.2639868234126642E7,2521209.7518529375,1.2640134335873192E7,2520214.531766677,1.2639318622250184E7,2518277.370534035,1.2639281121616814E7,2517457.1769566936,1.2641641838466672E7,2513069.2286300026,1.2641618831336396E7,2509260.1706670662,1.2642288711790182E7,2508428.1277619065,1.2643524905171303E7,2508393.6369728744,1.2645390968912719E7,2509043.04681973,1.2646933640987486E7,2510262.8444903335,1.2647857237968339E7,2511822.5449093385,1.2647727785239397E7,2513191.8241602858,1.2645979860162511E7,2517520.266015528,1.2644176275078254E7,2520122.459431299"]
    strArray.forEach((str) => {
        if(str) {
            let array = [];
            let splitArray = str.split(',');
            for(let i =0, length = splitArray.length; i < length; i++) {
                array.push(coordtransform.wgs84togcj02(parseFloat(splitArray[i++]) , parseFloat(splitArray[i]) + 28000));
                // array.push([parseFloat(splitArray[i++]) , parseFloat(splitArray[i])]);

            }
            coordinateArray.push(array);
        }

    });

    return coordinateArray;
}


//随机生成color

function createColorArray() {
    return [Math.floor(Math.random() * 255), Math.floor(Math.random() * 255), Math.floor(Math.random() * 255)]
}


// 重新包装fetch( 返回的结果是否自动json)

let _fetch = window.fetch;

fetch = (arg1, arg2) => {
  return _fetch(arg1, {
      credentials: 'include',...arg2}).then(res => res.json());
};

// add by yanyj 20180703 end